﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BL;
using Data;
using BaseUI;
using IUI;

namespace WebUI
{
    public partial class MainPage : //System.Web.UI.Page
                                    BaseWebPage<MainPageController>, IMainPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.SetUserID(Request.QueryString["login"]);
            if (User.IsAdmin)
            {
                btnAdmin.Enabled = true;
                btnAdmin.Visible = true;
            }
        }

        private String _userID;

        private event EventHandler _click_AdminButton;

        protected void btnAdmin_Click(object sender, EventArgs e)
        {
            if (_click_AdminButton != null) _click_AdminButton(this, null);
        }

        #region Реализация IMainPage

        public EventHandler ClickAdminButton
        {
            get { return _click_AdminButton; }
            set { _click_AdminButton = value; }
        }

        public string UserID
        {
            get { return _userID; }
        }

        public User User
        {
            get { return User.GetByName(_userID); }
        }

        public void SetUserID(string id)
        {
            if (null == _userID)
                _userID = id;
        }

        public void OpenAdminPage()
        {
            this.Response.Redirect("/AdminPage.aspx?" + "login=" + this.UserID);
        }

        #endregion
    }
}
